package shenlong.android.motorkeeper.key.adapter;

import java.util.List;

import shenlong.android.motorkeeper.key.dto.BTDevice;
import shenlong.android.motorkeeper.R;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class BTAdapter extends BaseAdapter {

	private Activity activity;
	private List<BTDevice> bluetoothDevices;
	public BTAdapter(Activity activity, List<BTDevice> btDevices)
	{
		this.activity = activity;
		this.bluetoothDevices = btDevices;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		int count = bluetoothDevices.size();
		return count;
	}

	@Override
	public Object getItem(int index) {
		// TODO Auto-generated method stub
		Object item = bluetoothDevices.get(index);
		return item;
	}

	@Override
	public long getItemId(int id) {
		// TODO Auto-generated method stub
		return id;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
        if(convertView == null)
        {
        	holder				=	new ViewHolder();
        	convertView		=	LayoutInflater.from(activity).inflate(R.layout.bt_list_item, null);
        	holder.text		=	(TextView) convertView.findViewById(R.id.bt_list_item_text);
        	holder.image		=	(ImageView) convertView.findViewById(R.id.bt_list_item_image);
        	convertView.setTag(holder);
        }
        else
        {
        	holder			=	(ViewHolder) convertView.getTag();
        }
        BTDevice device = bluetoothDevices.get(position);
        holder.text.setText(device.getSummary());
		return convertView;
	}
	public static class ViewHolder{
		TextView text;
		ImageView image;
		
	}
}
